//
//  DZPrivateDetailViewController.m
//  DaZhePrivateHomeCuisineClient
//
//  Created by zouzhisheng on 15-3-4.
//  Copyright (c) 2015年 zouzhisheng. All rights reserved.
//

#import "DZPrivateDetailViewController.h"

@interface DZPrivateDetailViewController (){
    float initHeight;
}

@end

@implementation DZPrivateDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    initHeight=44;
    self.navigationController.navigationBarHidden=YES;
    if (SharedAppDelegate.home.tabBarController) {
        [SharedAppDelegate.home.tabBarController setTabBarHidden:YES];
    }
    [self navView];
    [self addTitle:self.subject];
    [self loadData];

    // Do any additional setup after loading the view.
}
-(void)loadWebView:(NSString*)htmlStr{
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,self.navView.bottom,SCREEN_WIDTH,SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-49:SCREEN_HEIGHT-20-49)]; // 初始化浏览器控件UIWebView
    [_webView loadHTMLString:htmlStr baseURL:nil];
    [self.view addSubview:_webView];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)backAction:(UIButton *)bt{
    [SharedAppDelegate.home.tabBarController setTabBarHidden:NO];
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)loadData{
    NSDictionary *dir=[NSDictionary dictionaryWithObjectsAndKeys:@"detail",@"act",self.articleid,@"articleid", nil];
    [[BaseService shareNetworkService] requestActivityParameters:dir DataSouce:self RequestType:Request_DaZheDetailInfo Block:^(__weak id data, NSError *error) {
        if (!error) {
            DZSiFangCaiInfoModel *model=data;
            self.caiInfoSubModel=model.SiFangCaiInfo[0];
            NSString *htmlstr=[Common changeToHtmlStr:self.caiInfoSubModel.content];
            NSString *htmlString=[self insertImageURl:self.caiInfoSubModel.picture htmlStr:htmlstr];
            [self loadWebView:htmlString];
           // [self loadSubView];
        }
        
    }];
}
-(NSString*)insertImageURl:(NSString *)imageStr htmlStr:(NSString*)htmlStr{
    NSMutableString *htmlString=[[NSMutableString alloc] initWithCapacity:0];
    [htmlString appendString:@"<p class='MsoNormal' align='left' style='background-color:white;vertical-align:baseline;'>   <span style='font-size:12px;color:#333333;'><img width='320' src="];
    [htmlString appendString:[NSString stringWithFormat:@"'%@' alt='' /></span>  </p>",imageStr]];
    [htmlString appendString:htmlStr];
    return htmlString;
}
-(void)loadSubView
{
    [self.view addSubview:self.listView];
}
-(UITableView *)listView
{
    if (!_listView) {
        _listView=[[UITableView alloc] initWithFrame:CGRectMake(0,self.navView.bottom,SCREEN_WIDTH,SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20) style:UITableViewStylePlain];
        _listView.delegate=self;
        _listView.dataSource=self;
        _listView.backgroundColor=[UIColor clearColor];
        _listView.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return _listView;
}
#pragma mark-UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            static NSString *cellIdentifier=@"DZImageHeadTableViewCell";
            DZImageHeadTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (!cell) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"DZImageHeadTableViewCell"  owner:self options:nil] lastObject];
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell loadImageView:self.caiInfoSubModel.picture];
            return cell;
 
        }
            break;
        case 1:
        {
            static NSString *cellIdentifier=@"DZWebTableViewCell";
            DZWebTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (!cell) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"DZWebTableViewCell"  owner:self options:nil] lastObject];
            }
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            [cell loadWebView:[Common changeToHtmlStr:self.caiInfoSubModel.content]];
            return cell;
  
        }
            break;
            
        default:
            return nil;
            break;
    }
    
}

#pragma mark-UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            return 144;
            break;
        case 1:
            return initHeight;
            break;
            
        default:
            return 0;
            break;
    }

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (UIView *)viewForLoadAnimationAtService:(RequestType)type{
    return self.view;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)reloadTableViewHeight:(float)newHeight{
    initHeight=newHeight+25;
    [_listView beginUpdates];
    [_listView endUpdates];
}
@end
